package com.wsd.jing.controller.system;

import com.wsd.jing.annotation.ControllerLog;
import com.wsd.jing.entity.DictionaryDetail;
import com.wsd.jing.request.CommonRequest;
import com.wsd.jing.request.CommonResponse;
import com.wsd.jing.service.IDictionaryDetailService;
import com.wsd.jing.validator.group.InsertGroup;
import com.wsd.jing.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * All rights Reserved, Designed By www.tom.com
 *
 * @author tom
 * @version 1.0.0
 * @projectName: jing
 * @packageName: com.wsd.jing.controller
 * @className: DictionaryDetailController
 * @description: 数据字典详情前端控制器
 * @createDate 2022-11-29 04:06
 * @copyright 2022-11-29 04:06 www.tom.com Inc. All rights reserved.
 */
@Api(tags = "数据字典详情")
@Validated
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/rest/dictionary-detail")
public class DictionaryDetailController {

    private final IDictionaryDetailService dictionaryDetailService;

    @ApiOperation(value = "新增")
    @PostMapping()
    @ControllerLog(action = "新增数据字典详情", message = "新增数据字典详情失败")
    // @SaCheckPermission("dictionaryDetail:add")
    public CommonResponse insertDictionaryDetail(@Validated(InsertGroup.class) @RequestBody DictionaryDetail dictionaryDetail) {
        return CommonResponse.success(dictionaryDetailService.insertDictionaryDetail(dictionaryDetail), "新增成功");
    }

    @ApiOperation(value = "修改")
    @PutMapping()
    @ControllerLog(action = "修改数据字典详情", message = "修改数据字典详情失败")
    // @SaCheckPermission("dictionaryDetail:update")
    public CommonResponse updateDictionaryDetail(@Validated(UpdateGroup.class) @RequestBody DictionaryDetail dictionaryDetail) {
        return CommonResponse.success(dictionaryDetailService.updateDictionaryDetail(dictionaryDetail), "修改成功");
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id", value = "数据字典详情id", paramType = "path", dataType = "Integer", required = true)
    @DeleteMapping("/{id}")
    @ControllerLog(action = "删除数据字典详情", message = "删除数据字典详情失败")
    // @SaCheckPermission("dictionaryDetail:delete")
    public CommonResponse deleteDictionaryDetail(@PathVariable("id") Integer id) {
        return CommonResponse.success(dictionaryDetailService.deleteDictionaryDetail(id), "删除成功");
    }

    @ApiOperation(value = "批量删除")
    @ApiImplicitParam(name = "ids", value = "数据字典详情id逗号分割字符", paramType = "query", dataType = "String", required = true)
    @DeleteMapping("")
    @ControllerLog(action = "批量删除数据字典详情", message = "批量删除数据字典详情失败")
    // @SaCheckPermission("dictionaryDetail:batch:delete")
    public CommonResponse deleteDictionaryDetails(@RequestParam("ids") String ids) {
        return CommonResponse.success(dictionaryDetailService.deleteDictionaryDetails(ids), "批量删除成功");
    }

    @ApiOperation(value = "查询")
    @ApiImplicitParam(name = "id", value = "数据字典详情id", paramType = "path", dataType = "Integer", required = true)
    @GetMapping("/{id}")
    @ControllerLog(action = "查询数据字典详情", message = "查询数据字典详情失败")
    // @SaCheckPermission("dictionaryDetail:get")
    public CommonResponse getDictionaryDetail(@PathVariable("id") Integer id) {
        return CommonResponse.success(dictionaryDetailService.getDictionaryDetail(id), "查询成功");
    }

    @ApiOperation(value = "查询列表")
    @GetMapping("/list")
    @ControllerLog(action = "查询数据字典详情列表", message = "查询数据字典列表失败")
    // @SaCheckPermission("dictionaryDetail:list")
    public CommonResponse listDictionaryDetails(CommonRequest commonRequest, DictionaryDetail dictionaryDetail) {
        return CommonResponse.success(dictionaryDetailService.listDictionaryDetails(commonRequest, dictionaryDetail), "查询成功");
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/pages")
    @ControllerLog(action = "分页查询数据字典详情", message = "分页查询数据字典详情失败")
    // @SaCheckPermission("dictionaryDetail:page")
    public CommonResponse listPageDictionaryDetails(CommonRequest commonRequest, DictionaryDetail dictionaryDetail) {
        return CommonResponse.success(dictionaryDetailService.listPageDictionaryDetails(commonRequest, dictionaryDetail), "查询成功");
    }
}
